package ControlLayer;

import java.util.ArrayList;

import DBLayer.DBCustomer;
import DBLayer.DBEmployee;
import ModelLayer.Customer;
import ModelLayer.Employee;

public class CtrPerson 
	{
	
		public int insertCus(String name, String adress, String zipCode, String city, String phoneNo, String email, String cvrNo, String accountNo) throws Exception 
			{
			Customer cus = new Customer();
			int i = 0;
			
			cus.setIdCustomer("nextIdCustomer");
			cus.setName(name);
			cus.setAddress(adress);
			cus.setZipCode(zipCode);
			cus.setCity(city);
			cus.setPhoneNo(phoneNo);
			cus.setEmail(email);
			cus.setCvrNo(cvrNo);
			cus.setAccountNo(accountNo);
			
			DBCustomer dbCus = new DBCustomer();
			i = dbCus.insertCustomer(cus);
			
			return i;
			
			
			}
	
		public int insertEmp(String name, String adress, String zipCode, String city, String phoneNo, String email, String cpr, String bankAccountNo, double hourlyWage) throws Exception 
			{
				Employee emp = new Employee();
				int i = 0;
				
				emp.setIdEmployee("nextIdEmployee");
				emp.setName(name);
				emp.setAddress(adress);
				emp.setZipCode(zipCode);
				emp.setCity(city);
				emp.setPhoneNo(phoneNo);
				emp.setEmail(email);
				emp.setCpr(cpr);
				emp.setHourlyWage(hourlyWage);
				emp.setBankAccountNo(bankAccountNo);
				
				DBEmployee dbEmp = new DBEmployee();
				i = dbEmp.insertEmployee(emp);
				
				return i;
			}
		
		public ArrayList<Customer> getAllCus() throws Exception
			{
				ArrayList<Customer> cusList= new ArrayList<Customer>();
				DBCustomer dbCus = new DBCustomer();
				cusList = dbCus.getAllCustomers();
				
				return cusList;
			
			}
		
		public ArrayList<Employee> getAllEmp() throws Exception
			{
				ArrayList<Employee> empList= new ArrayList<Employee>();
				DBEmployee dbEmp = new DBEmployee();
				empList = dbEmp.getAllEmployees();
				
				return empList;
			
			}
		
		public Customer findCus(String idCustomer) throws Exception
			{
				Customer cus = new Customer();
				DBCustomer dbEmp = new DBCustomer();
				cus = dbEmp.findCustomerById(idCustomer);
							
				return cus;
			}
		
		public Employee findEmp(String idEmployee) throws Exception
			{
				Employee emp = new Employee();
				DBEmployee dbEmp = new DBEmployee();
				emp = dbEmp.findEmployeeById(idEmployee);
				
				return emp;
			}
		
		public int cusUpdate(String idCustomer, String name, String address, String zipCode, String city, String phoneNo, String email, String cvrNo, String accountNo) throws Exception 
		{
			Customer cus = new Customer();
			DBCustomer dbCus = new DBCustomer();
			cus = dbCus.findCustomerById(idCustomer);
			int i = 0;
			if(cus != null)
			{
				cus.setName(name);
				cus.setAddress(address);
				cus.setZipCode(zipCode);
				cus.setPhoneNo(phoneNo);
				cus.setEmail(email);
				cus.setCvrNo(cvrNo);
				cus.setAccountNo(accountNo);
							
				i = dbCus.updateCustomer(cus);
			}
			
			return i;
			
		}
		
		public int empUpdate(String idCustomer, String name, String address, String zipCode, String city, String phoneNo, String email, String cvrNo, String accountNo) throws Exception 
		{
			Customer cus = new Customer();
			DBCustomer dbCus = new DBCustomer();
			cus = dbCus.findCustomerById(idCustomer);
			int i = 0;
		
			if(cus != null)
			{
				cus.setName(name);
				cus.setAddress(address);
				cus.setZipCode(zipCode);
				cus.setPhoneNo(phoneNo);
				cus.setEmail(email);
				cus.setCvrNo(cvrNo);
				cus.setAccountNo(accountNo);
							
				i = dbCus.updateCustomer(cus);
			}
			return i;
			
		}
		
		public int deleteCus(String idCustomer) throws Exception
			{
				Customer cus = new Customer();
				DBCustomer dbEmp = new DBCustomer();
				cus = dbEmp.findCustomerById(idCustomer);
				int i = 0;
				
				if(cus != null)
				{
					i = dbEmp.deleteCustomer(idCustomer);	
				
				}
				return i;
			}
		
		public int deleteEmp(String idEmployee) throws Exception
			{
				Employee emp = new Employee();
				DBEmployee dbEmp = new DBEmployee();
				emp = dbEmp.findEmployeeById(idEmployee);
				int i = 0;
				
				if(emp != null)
				{
					i = dbEmp.deleteEmployee(idEmployee);	
				
				}
				return i;
			}
		
		
		
		
	
}
